1. Field of the Invention
The present invention generally relates to data processing techniques and, in particular, to a system and method for detecting whether an instruction of a computer program function, if executed, will access a memory location that has not been allocated to the computer program function.
2. Related Art
In executing instructions of computer programs, a conventional computer system typically divides the memory resources of the computer system among the various functions of the computer programs. For example, a computer system that is used to execute a first function and a second function of a computer program typically allocates a first portion of its memory to the first function and a second portion of its memory to the second function. During operation, the first function may store to and/or retrieve data from the first portion of memory that is allocated to the first function, and the second function may store to and/or retrieve data from the second portion of memory that is allocated to the second function.
A data error may occur if a function attempts to access a memory location outside of the memory allocated to the function. For example, the aforementioned first function may temporarily store a data value in the memory that is allocated to the first portion. At a later time, the first function may retrieve this data value and utilize this data value to perform an operation. However, between the times that the data value is stored and retrieved by the first function, the aforementioned second function may erroneously overwrite the foregoing data value with another data value, even though the second function should only store data to the memory that is allocated to the second function. As a result of the second function improperly overwriting the data value stored by the first function, the first function retrieves the data value stored by the second function instead of the data value previously stored by the first function. In other words, the first function retrieves the wrong data value. The retrieval of the wrong data value may result in a data error that causes the first function to operate incorrectly.
The cause of this data error is very difficult to detect because the error occurs in the first function, which does not include the bug that caused the error. In this regard, the bug probably exists in the second function, even though the error occurs in the first function. Thus, a programmer may attempt to debug the first function when the programmer should really be focusing on the second function.
In another example, the second function may erroneously read a value from a location within the memory allocated to the first function. Therefore, the second function may read an incorrect data value, which may cause a data error in the second function. This type of bug is a little easier to detect since the function that experiences the data error is the same function that caused the data error. Nevertheless, it is desirable to detect and prevent such data errors, when possible.
Thus, a heretofore unaddressed need exists in the industry for providing a system and method for detecting and/or preventing data errors caused by a function attempting to access a memory location outside of the memory allocated to the function.
The present invention overcomes the inadequacies and deficiencies of the prior art as discussed hereinbefore. Generally, the present invention provides a system and method for detecting whether an instruction of a function, if executed, will access a memory location that has not been allocated to the function.
In architecture, the system of the present invention utilizes memory, a memory device, and circuitry that is configured to process and execute instructions of computer programs. The memory device is loaded with data indicative of which locations of the memory are allocated to a computer program function. The circuitry is configured to detect, based on the data, whether a memory location to be accessed via execution of an instruction of the function is one of the memory locations allocated to the function.
In accordance with a feature of the present invention, the circuitry prevents execution of the instruction when the circuitry detects that a memory location to be accessed via execution of the instruction is not one of the memory locations allocated to the function. Preventing execution of such instructions may be selective based on a run time input.
In accordance with another feature of the present invention, an error message is displayed to a user of the system when the circuitry detects that a memory location to be accessed via execution of the instruction is not one of the memory locations allocated to the function.
In accordance with another feature of the present invention, the data indicating which memory locations are allocated to the function is updated when additional memory locations are allocated to the function.
The present invention can also be viewed as providing a method for detecting attempts by a function to access memory that has not been allocated to the function. The method can be broadly conceptualized by the following steps: providing memory and a processor pipeline; allocating memory locations of the memory to a computer program function; storing data indicative of which memory locations of the memory are allocated to the function; detecting, based on the data, whether an instruction of the function, if executed, accesses one of the memory locations allocated to the function; and disabling the pipeline from executing the instruction while the pipeline is processing the instruction and in response to a detection in the detecting step that the instruction, if executed, accesses a memory location that has not been allocated to the function.